package cc.wanforme.st.server.base.service.impl;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import cc.wanforme.st.server.base.entity.AuthToken;
import cc.wanforme.st.server.base.mapper.AuthTokenMapper;
import cc.wanforme.st.server.base.service.IAuthTokenService;


/**
 * @author wanne
 * 2020年10月23日
 */
@Service
public class AuthTokenServiceImpl extends ServiceImpl<AuthTokenMapper, AuthToken> implements IAuthTokenService{

	@Override
	public AuthToken selecToken(String token) {
//		QueryWrapper<AuthToken> wrapper = new QueryWrapper<AuthToken>();
//		wrapper.eq("token", token);
		return this.baseMapper.selecToken(token);
	}

	@Override
	public List<AuthToken> selecUserToken(long userId) {
		return this.baseMapper.selectUserToken(userId);
	}

	public AuthToken saveRecord(long userId, String token, String host, int validDays, String type) {
		LocalDateTime now = LocalDateTime.now();
		AuthToken authToken = new AuthToken();
		authToken.setUserId(userId);
		authToken.setToken(token);
		authToken.setHost(host);
		authToken.setCreateTime(now);
		authToken.setExpireTime(now.plusDays(validDays));
		authToken.setType(type);
		this.save(authToken);
		return authToken;
	}
	
}
